<?php
class UserDressVo extends SzAbstractMySqlVo
{

    private $userId;
    private $type;
    private $stock;
    private $createTime;
    private $updateTime;

    /**
     * Initialize UserDressVo.
     *
     * @param $userId
     * @param $type
     * @param $stock
     * @param $createTime
     * @param $updateTime
     * @param boolean $isInsert default false, means for now this vo is initialized not for insert process
     * @return UserDressVo
     */
    public function __construct($userId, $type, $stock, $createTime, $updateTime, $isInsert = false) {
        $this->userId = $userId;
        $this->type = $type;
        $this->stock = json_decode($stock, true);
        $this->createTime = $createTime;
        $this->updateTime = $updateTime;

        $this->isInsert = $isInsert;
        $this->voClassName = 'UserDressVo';
        $this->ormName = 'UserDress';
    }

    /**
     * @see SzAbstractVo::toArray
     */
    public function toArray($needEncode = false)
    {
        return array(
            'userId' => $this->getUserId(),
            'type' => $this->getType(),
            'stock' => ($needEncode) ? $this->getStock() : $this->getRawStock(),
            'createTime' => $this->getCreateTime(),
            'updateTime' => $this->getUpdateTime(),
        );
    }

    /**
     * @see SzAbstractVo::toEntireArray
     */
    public function toEntireArray($needEncode = false)
    {
        return array(
            'userId' => $this->getUserId(),
            'type' => $this->getType(),
            'stock' => ($needEncode) ? $this->getStock() : $this->getRawStock(),
            'createTime' => $this->getCreateTime(),
            'updateTime' => $this->getUpdateTime(),
        );
    }

    /**
     * @see SzAbstractVo::toPureArray
     */
    public function toPureArray()
    {
        return array(
            $this->getUserId(),
            $this->getType(),
            $this->getStock(),
            $this->getCreateTime(),
            $this->getUpdateTime(),
        );
    }

    public function getUserId()
    {
        return $this->userId;
    }

    public function setUserId($val)
    {
        $this->saveColumnStatus(0, $this->userId);
        $this->userId = $val;
    }

    public function getType()
    {
        return $this->type;
    }

    public function setType($val)
    {
        $this->saveColumnStatus(1, $this->type);
        $this->type = $val;
    }

    public function getStock()
    {
        return json_encode($this->stock);
    }

    public function getRawStock()
    {
        return $this->stock;
    }

    public function setStock($val)
    {
        $encodedLength = SzUtility::strLen(json_encode($val));
        if ($encodedLength > 25600) {
            SzLogger::get()->error('[UserDressVo] The length of column stock exceed the limit, length / limit: ' . $encodedLength . ' / 25600');
            throw new SzException(10522, array('UserDressVo', '25600', $encodedLength));
        } else if ($encodedLength > 23040) {
            SzLogger::get()->warn('[UserDressVo] The length of column stock exceed the warning level, length / limit: ' . $encodedLength . ' / 25600');
        }
        $this->saveColumnStatus(2, $this->stock);
        $this->stock = $val;
    }

    public function getCreateTime()
    {
        return $this->createTime;
    }

    public function setCreateTime($val)
    {
        $this->saveColumnStatus(3, $this->createTime);
        $this->createTime = $val;
    }

    public function getUpdateTime()
    {
        return $this->updateTime;
    }

    public function setUpdateTime($val)
    {
        $this->saveColumnStatus(4, $this->updateTime);
        $this->updateTime = $val;
    }

}